package com.jianneng.jdg.model.adapter;

import java.util.ArrayList;
import java.util.List;

import com.example.com.jianneng.jdg.R;
import com.jianneng.jdg.model.user.ActivitiesInfo;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivitiesListAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater mInflater;
	private List<ActivitiesInfo> list = new ArrayList<ActivitiesInfo>();

	public ActivitiesListAdapter(Context context, List<ActivitiesInfo> list) {
		this.context = context;
		this.list = list;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder mHolder = null;
		if (convertView == null) {
			mHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.activities_listview_item, null);
			mHolder.time = (TextView) convertView.findViewById(R.id.activities_time);
			mHolder.title = (TextView) convertView.findViewById(R.id.activities_title);
			mHolder.image = (ImageView) convertView
					.findViewById(R.id.activities_image);
			mHolder.content = (TextView) convertView
					.findViewById(R.id.activities_content);
			// 绑到View
			convertView.setTag(mHolder);
		} else {
			// 重用View
			// 重用holder
			mHolder = (ViewHolder) convertView.getTag();
		}
		// 得到数据
		ActivitiesInfo info = list.get(position);
		System.out.println(info.toString()+"11111111111");
		mHolder.time.setText(info.getTime());
		mHolder.title.setText(info.getTitle());
		mHolder.image.setImageResource(R.drawable.ic_launcher);
		mHolder.content.setText(info.getContent());
		return convertView;
	}
	public static class ViewHolder {
		TextView time;
		TextView title;
		ImageView image;
		TextView content;

	}

}
